package nsga.comparison;

import java.util.ArrayList;
import java.util.List;

import nsga.comparison.util.DBDAO;
import nsga.comparison.util.MetricsUtil;

public class DataSource {
	DBDAO dbDAO = new DBDAO();
	MetricsUtil metricUtil = new MetricsUtil();
	/**
	 * 从数据库中读到我们方法目标值集合，再计算出front
	 * @param runID
	 * @param genID
	 * @return
	 */
	public ArrayList<ArrayList<Float>> getMyMethodFront(String runID,String genID) {
		ArrayList<ArrayList<Float>> rlt = new ArrayList<ArrayList<Float>>();
		ArrayList<ArrayList<Float>> temp = dbDAO.getObjVals(runID, genID);		
		rlt = metricUtil.getFrontByObjvals(temp);					
		return rlt;
	}

	/**
	 * 从数据库中读到PCM方法目标值集合，再计算出front
	 * @param runID
	 * @param genID
	 * @return
	 */
	public ArrayList<ArrayList<Float>> getPCMMethodFront(String runID,String genID) {
		ArrayList<ArrayList<Float>> rlt = new ArrayList<ArrayList<Float>>();
		ArrayList<ArrayList<Float>> temp = dbDAO.getObjVals(runID, genID);
		rlt = metricUtil.getFrontByObjvals(temp);		
		return rlt;
	}
	
	public static void main(String[] args){
		DataSource dataSource = new DataSource();
		String runID = "NSRulSeqGAd17128cb-0afe-4683-a4a7-57b4417bf56f";
		String genID = "200";
		ArrayList<ArrayList<Float>> rlt = dataSource.getMyMethodFront(runID, genID);
		System.out.println(rlt.size());
	}
	
	/**
	 * 计算参考pareto前沿
	 * @param runIDs
	 * @param genID
	 * @return
	 */
//	public ArrayList<ArrayList<Float>> getRefFrontFront(List<String> runIDs,String genID) {
//		ArrayList<ArrayList<Float>> refFront = new ArrayList<ArrayList<Float>>();
//		ArrayList<ArrayList<Float>> temp = new ArrayList<ArrayList<Float>>();
//		
//		
//		for(String runID:runIDs){
//			ArrayList<ArrayList<Float>> temp2 = new ArrayList<ArrayList<Float>>();
//			temp2 = dbDAO.getObjVals(runID, genID);
//			ArrayList<ArrayList<Float>> rlt = metricUtil.getFrontByObjvals(temp2);
//			for(ArrayList<Float> oneRlt:rlt){
//				temp.add(oneRlt);
//			}
//		}
//		refFront = metricUtil.getFrontByObjvals(temp);
//		return refFront;
//	}
	
	public ArrayList<ArrayList<Float>> getRefFrontFront(List<String> runIDs,String genID) {
		ArrayList<ArrayList<Float>> refFront = new ArrayList<ArrayList<Float>>();
		ArrayList<ArrayList<Float>> rlt   = new ArrayList<ArrayList<Float>>();
				
		for(String runID:runIDs){
			ArrayList<ArrayList<Float>> temp = new ArrayList<ArrayList<Float>>();
			temp = dbDAO.getObjVals(runID, genID);
			ArrayList<ArrayList<Float>> temp2 = metricUtil.getFrontByObjvals(temp);
			for(ArrayList<Float> oneRlt:temp2){
				rlt.add(oneRlt);
			}
		}
		refFront = metricUtil.getFrontByObjvals(rlt);
		return refFront;
	}
	
}
